import { defineStore } from 'pinia'
import { addMenu, deleteMenu, editMenu, getMenuTree } from '@/service/index.js'
import responseMessage from '@/utils/response.js'

const useMenuStore = defineStore('menu', {
  state: () => ({
    menuTree: ''
  }),
  actions: {
    //获取部门树
    async getMenuTreeAction(searchParams) {
      const res = await getMenuTree(searchParams)
      this.menuTree = res.data
    },
    //添加
    async addMenu(addForm) {
      const res = await addMenu(addForm)
      responseMessage(res)
    },
    //编辑菜单
    async editMenu(addForm) {
      const res = await editMenu(addForm)
      responseMessage(res)
    },
    //删除菜单
    async deleteMenu(id) {
      const res = await deleteMenu(id)
      responseMessage(res)
    }
  }
})

export default useMenuStore
